package com.ytjj.qmyx.admin.controller.imController;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.vo.ImServiceUserVO;
import com.ytjj.qmyx.admin.service.imService.ImServiceUserService;
import com.ytjj.qmyx.admin.utils.UserUtil;
import com.ytjj.qmyx.users.model.ImServiceUserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 客服管理controller
 */
@RestController
@RequestMapping("/imService")
@Slf4j
public class ImServiceUserController {

    @Autowired
    private ImServiceUserService imServiceUserService;

    /**
     *  获取客服状态
     * @return
     */
    @GetMapping("/getUserStatus")
    public CommonResult getUserStatus(){
        String userId = UserUtil.getPrincipal();
        return CommonResult.success(imServiceUserService.getUserStatus(userId));
    }

    /**
     *  修改客服状态
     * @param imServiceUserVO
     * @return
     */
    @PostMapping("/updateUserStatus")
    public CommonResult updateUserStatus(@RequestBody ImServiceUserVO imServiceUserVO){
        if (StringUtils.isEmpty(imServiceUserVO.getUserId())){
            String userId = UserUtil.getPrincipal();
            imServiceUserVO.setUserId(userId);
        }
        return CommonResult.success(imServiceUserService.updateUserStatus(imServiceUserVO));
    }

    @PostMapping("/updateUserStatusByRpc")
    public void updateUserStatusByRpc(@RequestBody ImServiceUserDto imServiceUserDto){
        ImServiceUserVO imServiceUserVO = new ImServiceUserVO();
        if (null != imServiceUserDto) {
            BeanUtils.copyProperties(imServiceUserDto, imServiceUserVO);
        }
        if (StringUtils.isEmpty(imServiceUserVO.getUserId())){
            String userId = UserUtil.getPrincipal();
            imServiceUserVO.setUserId(userId);
        }
        imServiceUserService.updateUserStatus(imServiceUserVO);
    }
}
